package com.bestvike.stone.spring.redis;

import com.bestvike.stone.core.threading.ThreadPool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * Created by 许崇雷 on 2018/6/19.
 */
@Configuration
@ConditionalOnClass(RedisMessageListenerContainer.class)
public class RedisMessageListenerContainerAutoConfiguration {
    @Bean
    @Primary
    @ConditionalOnMissingBean
    public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setTaskExecutor(ThreadPool.getExecutor());
        container.setSubscriptionExecutor(ThreadPool.getExecutor());
        return container;
    }
}
